<!--
+----------------------------------------------------------------------
| 友得云客  - 开启房产营销新纪元
+----------------------------------------------------------------------
| Copyright (c) 2019~2023 优得（西安）信息科技有限公司版权所有
+----------------------------------------------------------------------
| Licensed 友得云客不是自由软件 未经允许不可移除相关版权
+----------------------------------------------------------------------
| Author: www.youdeyunke.com
+----------------------------------------------------------------------
-->
<template>
    <div v-loading="loading" class="user-groups" v-cloak>
        <el-table :data="items" :show-header="false">
            <el-table-column label="名称" prop="name" :width="200">
                <template slot-scope="scope">
                    <span>
                        {{ scope.row.name }} <i title="系统默认分组，不可删除" class="el-icon-lock" v-if="scope.row.is_system" />
                    </span>
                </template>
            </el-table-column>
            <el-table-column label="备注" prop="remark"></el-table-column>
            <el-table-column label="用户数" prop="user_count" :width="80"></el-table-column>
            <el-table-column label="操作" :width="100">
                <template slot-scope="scope">
                    <el-link type="primary" @click="$emit('edit', scope.row)">编辑</el-link>
                    <el-link :disabled="scope.row.is_system" type="danger" @click="deleteHandle(scope.row)">删除</el-link>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>

<script>
import { getUserGroupList, deleteUserGroup } from "@/api/user";
export default {
    data () {
        return {
            loading: true,
            items: [],
        };
    },
    props: {
        cat: { type: String, default: "broker" },
    },

    mounted: function () {
        this.loadData();
    },

    computed: {},

    methods: {
        deleteHandle: function (item) {
            this.$confirm("确定要删除这个分组吗", "删除提示").then(() => {
                deleteUserGroup(item.id).then((resp) => {
                    this.loading = false;
                    if (resp.status == 0) {
                        this.$message.success("已删除");
                        this.loadData();
                    }
                });
            });
        },
        loadData: function () {
            this.loading = true;
            var query = { cat: this.cat };
            getUserGroupList(query).then((resp) => {
                this.loading = false;
                if (resp.status === 0) {
                    this.items = resp.data;
                }
            });
        },
    },
};
</script>

<style scoped></style>